import numpy as np


def generate_data():
    # 假设做题时间越长, 正确率越高
    used_time = abs(np.random.randn(1000) * 100).astype(int)
    correct_count = softmax(used_time)
    score = correct_count * 100 - np.random.uniform(1, 4)
    x_train = np.vstack((used_time, score)).T
    x_train = x_train.reshape(1000, 2, 1)
    y_train = score.reshape(1000, 1, 1)
    return x_train, y_train


def softmax(x):
    x = np.array(x)
    x = np.exp(x)
    x.astype('float32')
    if x.ndim == 1:
        sum_col = sum(x)
        for i in range(x.size):
            x[i] = x[i] / float(sum_col)
    if x.ndim > 1:
        sum_col = x.sum(axis=0)
        for row in x:
            for i in range(row.size):
                row[i] = row[i] / float(sum_col[i])
    return x
